﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using libInventory.BUS ;
using Telerik.WinControls.Data;
using Telerik.WinControls.UI;
using libDAL;
using libCommonTools.Forms;
using libCommonTools.BUS;

namespace libInventory.FORMS
{
    public partial class frmAdditionalServices : Telerik.WinControls.UI.RadForm
    {
        private clsInterfaceAdditionalServices _BUS;
        private string strGoodReceivedNote = string.Empty;
        private string strSalesTermSetupHeaderID = string.Empty;
        private string strSalesTermAdditionalHeaderID = string.Empty;
        private string str3rdParty = string.Empty;
        private string strPortID = string.Empty;
        private DataTable dtCharges;
        private DataTable dtOrigin;
        private DataTable dtDestination;
        private bool bolApplied = false;
        public frmAdditionalServices()
        {
            InitializeComponent();
            _BUS = new clsInterfaceAdditionalServices();
        }

        public string getset_PortID
        {
            get
            {
                return this.strPortID;
            }
            set
            {
                this.strPortID = value;
            }
        }

        public string getset_SalesTermSetupHeaderID
        {
            get
            {
                return strSalesTermSetupHeaderID;
            }
            set
            {
                this.strSalesTermSetupHeaderID = value;
            }
        }

        public string get_SalesTermAdditionalHeaderID
        {
            get
            {
                return this.strSalesTermAdditionalHeaderID;
            }
            set
            {
                //this.strSalesTermAdditionalHeaderID;
                this.strSalesTermAdditionalHeaderID = value;
            }
        }

        private void set_LoadExistingTransactions()
        {
            try
            {
               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadExistingTransactions"); 
            }
        }

        public DataRow[] get_OriginAdditionalCharges()
        {
           return _BUS.get_OriginAdditionalCharges();
           
        }

        public DataRow[] get_DestinationAdditionalCharges()
        {
            return _BUS.get_DestinationAdditionalCharges();
        }


        public clsInterfaceAdditionalServices get_AdditionalServicesBUS
        {
            get
            {
                return _BUS;
            }
        }

        public string getset_GoodReceivedNote
        {
            get
            {
                return _BUS.getset_GoodReceivedNote;
            }
            set
            {
                _BUS.getset_GoodReceivedNote = value;
            }
        }

        private void set_RowHeight()
        {
            ((GridTableElement)this.dgvAdditionalChargesOrigin.TableElement).RowHeight = 20;
            ((GridTableElement)this.dgvAdditionalChargesDestination.TableElement).RowHeight = 20;
        }

        private void set_GridSettings()
        {
            try
            {
                GridViewComboBoxColumn comboCol = new GridViewComboBoxColumn("ChargePaidBy");
                comboCol.DataSource = new String[] { "", "Shipper", "Consignee", "3rd Party" };
                comboCol.FieldName = "ChargePaidBy";
                comboCol.HeaderText = "Paid By";
                comboCol.Width = 100;

                GridViewTextBoxColumn txtCell = new GridViewTextBoxColumn();
                txtCell.Name = "comid";
                txtCell.HeaderText = "Company ID";
                txtCell.Width = 100;
                txtCell.ReadOnly = true;

                dgvAdditionalChargesOrigin.Columns.Add(comboCol);
                dgvAdditionalChargesOrigin.Columns.Add(txtCell);

                dgvAdditionalChargesOrigin.Columns["CodeDescription"].Width = 230;
                dgvAdditionalChargesOrigin.Columns["ccitemcode"].Width = 100;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GridSettings"); 
            }
        }

        private void frmAdditionalServices_Load(object sender, EventArgs e)
        {
            try
            {
                set_GridSettings();
                dtCharges = new DataTable();
                set_RowHeight();
                set_LoadPortOrigin();
                set_LoadAdditionalServices();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " frmAdditionalServices_Load"); 
            }
           
        }

        private void set_LoadAdditionalServices()
        {
            try
            {
                if (getset_SalesTermSetupHeaderID.Trim() != string.Empty)
                { 
                   // this.dtCharges = 
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadAdditionalServices"); 
            }
        }

        private void set_LoadPortOrigin()
        {
            try
            {
                DataTable dt = new DataTable();
                if (_BUS.set_PaidHeaders() == true)
                {
                    dt = _BUS.get_PaidHeaders;
                    mcmbTransactions.EditorControl.LoadElementTree();
                    mcmbTransactions.DataSource = dt;

                    for (int intIndex = 0; intIndex < dt.Columns.Count; intIndex++)
                    {
                        mcmbTransactions.MultiColumnComboBoxElement.Columns[intIndex].BestFit();
                    }

                    mcmbTransactions.MultiColumnComboBoxElement.DropDownWidth = 300;
                    mcmbTransactions.MultiColumnComboBoxElement.DropDownHeight = 150;
                    mcmbTransactions.SelectedIndex = -1;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadPortOrigin");
            }
        }

        private bool set_LoadDetails()
        {
            bool bolStatus = false;
            try
            {
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadDetails"); 
            }
            return bolStatus;
        }

        public string set_ShipperID
        {
            set
            {
                txtShipperID.Text = value;
                _BUS.getset_ShipperID = value;
            }
        }

        public string set_ShipperName
        {
            set
            {
                txtShipperName.Text = value;
                
            }
        }

        public string set_ConsigneeID
        {
            set
            {
                txtConsigneeID.Text = value;
                _BUS.getset_ConsigneeID = value;
            }
        }

        public string set_ConsigneeName
        {

            set
            {
                txtConsigneeName.Text = value; 
            }
        }

        public string set_3rdPartyID
        {
            set
            {
                txt3rdPartyID.Text = value;
            }
        }

        public string set_3rdPartyName
        {
            set
            {
                txt3rdPartyName.Text = value; 
            }
        }

        public string set_3rdParty
        {
            get
            {
                return str3rdParty;
            }
            set
            {
                str3rdParty = value;
                _BUS.getset_3rdParty = value;
            }
        }

        

         

        private DataTable get_GridColumns(RadGridView dgvGrid)
        {
            DataTable dt = new DataTable();
            dt .Columns.Add ("ColName", typeof(string));
            DataRow drInsert;
            for (int intCol = 0; intCol < dgvGrid.Columns.Count; intCol++)
            {
                if (dgvGrid.Columns[intCol].Name.ToString().ToLower().Contains("column") == false)
                {
                    drInsert = dt.NewRow();
                    drInsert["ColName"] = dgvGrid.Columns[intCol].Name;
                    dt.Rows.Add(drInsert);
                }
            }
            return dt;
        }

        private bool set_LoadGridOriginDestinationRefToGrid(ref RadGridView dgvGrid, DataTable dtSource)
        {
            bool bolStatus = false;
            int intRow = 0;
            int intCol = 0;
            try
            {
                DataTable dtcolumns = get_GridColumns(dgvGrid);
                DataRow[] drCheck = { };
                GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
                for (intRow = 0; intRow < dtSource.Rows.Count; intRow++)
                {
                    //rowInfo
                    for (intCol = 0; intCol < dtSource.Columns.Count; intCol++)
                    {
                        //if (intCol == 27)
                        //{
                        //    string a = "";
                        //}
                        drCheck = dtcolumns.Select("ColName = '" + dtSource.Columns[intCol].ColumnName + "'");
                        if (drCheck.Length > 0)
                        {
                            if (dtSource.Columns[intCol].ColumnName != "ChargePaidBy")
                            {
                                dgvGrid.CurrentRow.Cells[dtSource.Columns[intCol].ColumnName].Value = dtSource.Rows[intRow][dtSource.Columns[intCol].ColumnName];

                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_LoadGridOriginDestinationRefToGrid"); 
            }
            return bolStatus;
        }

        private bool set_LoadGridOriginDestinationx(ref RadGridView dgvGrid, DataRow[] drSource)
        {
            bool bolStatus = false;
            try
            {
                if (dgvGrid.Rows.Count > 0)
                { 
                    dgvGrid.Rows.Clear(); 
                }

                GridViewDataRowInfo rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
                for (int intI = 0; intI < drSource.Length; intI++)
                {
                    rowInfo = new GridViewDataRowInfo(dgvGrid.MasterView);
                    for (int intC = 0; intC < dgvGrid.Columns.Count; intC++)
                    {
                        if (dgvGrid.Columns[intC].Name.ToString().Trim().ToLower().Contains("column") == false)
                        {
                            rowInfo.Cells[dgvGrid.Columns[intC].Name].Value = drSource[intI][dgvGrid.Columns[intC].Name];
                        }
                    }
                    dgvGrid.Rows.Add(rowInfo);
                }
                dgvGrid.BestFitColumns();
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException.Message + " set_LoadGridOriginDestination");
            }
            return bolStatus;
        }

        private void set_AdditionalServicesHeaderID()
        {
            if (get_SalesTermAdditionalHeaderID == string.Empty)
            {
                get_SalesTermAdditionalHeaderID = getset_SalesTermSetupHeaderID + "-" + mcmbTransactions.Text.Trim() + "-" + txtShipperID.Text.Trim() + "-" + txtConsigneeID.Text.Trim() + "-" + getset_GoodReceivedNote + "-" + clsGenFunction.get_GenKeyNEWID(_BUS.get_DAL).ToString();
            }
        }

        private DataTable get_GenerateColumns()
        {
            DataTable dtTempCols = new DataTable();
            try
            {
                for (int intCols = 0; intCols < dgvAdditionalChargesOrigin.Columns.Count; intCols++)
                {
                    if (dgvAdditionalChargesOrigin.Columns[intCols].Name.Trim().ToLower().Contains("column") == false)
                    {
                        dtTempCols.Columns.Add(dgvAdditionalChargesOrigin.Columns[intCols].Name.Trim());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_GenerateColumns"); 
            }
            return dtTempCols;
        }

        private void set_PayerID(ref RadGridView dgvSourceGrid, int intRow,string strChargeType)
        {
            try
            {
                if (strChargeType == "Shipper")
                {
                  //  dgvSourceGrid.Rows[intRow].Cells["ChargePaidBy"].Value = txtShipperID.Text.Trim();
                }
                else if (strChargeType == "Consignee")
                {
                  //  dgvSourceGrid.Rows[intRow].Cells["ChargePaidBy"].Value = txtConsigneeID.Text.Trim();
                }
                else if (strChargeType == "3rd Party" && txt3rdPartyID.Text.Trim() != string.Empty)
                {
                  //  dgvSourceGrid.Rows[intRow].Cells["ChargePaidBy"].Value = txt3rdPartyID.Text.Trim(); 
                }
                else if (strChargeType == "3rd Party" && txt3rdPartyID.Text.Trim() == string.Empty)
                {
                    MessageBox.Show("No Selected Third party."); 
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_PayerID"); 
            }
        }

        private bool get_TransferRecordsFromGrid(ref DataTable dtStorage,ref RadGridView dgvSourceGrid, string strConcatenated, string strType)
        {
            bool bolStatus = false;
            try
            {
                DataRow drInsert = dtStorage.NewRow();
                string strIDDetails = string.Empty ;

                for (int intRow =0 ; intRow < dgvSourceGrid.Rows.Count ; intRow++)
                {
                    drInsert = dtStorage.NewRow();
                    for (int intCol = 0; intCol < dgvSourceGrid.Columns.Count; intCol++)
                    {
                        if(dgvSourceGrid.Columns[intCol].Name.ToString() == "comid")
                        {
                            string a = string.Empty ;
                        }

                        if (dgvSourceGrid.Columns[intCol].Name.ToString().ToLower().Trim().Contains("column") == false)
                        {
                            if (dgvSourceGrid.Columns[intCol].Name.ToString().Trim().Contains("SalesTermAdditionalPaidDetailsID") == true)
                            {
                                strIDDetails = strConcatenated + "-" + getset_GoodReceivedNote + "-" + dgvSourceGrid.Rows[intRow].Cells["ccitemcode"].Value + "-" + clsGenFunction.get_GenKeyNEWID(_BUS.get_DAL).ToString(); 
                                drInsert[dgvSourceGrid.Columns[intCol].Name.ToString().Trim()] = strIDDetails;
                                dgvSourceGrid.Rows[intRow].Cells[dgvSourceGrid.Columns[intCol].Name].Value = strIDDetails;
                            }
                            else if (dgvSourceGrid.Columns[intCol].Name.ToString().Trim().Contains("SalesTermAdditionalPaidHeadersID") == true)
                            {
                                drInsert[dgvSourceGrid.Columns[intCol].Name.ToString().Trim()] = get_SalesTermAdditionalHeaderID;
                                dgvSourceGrid.Rows[intRow].Cells[dgvSourceGrid.Columns[intCol].Name].Value = get_SalesTermAdditionalHeaderID;
                                strIDDetails = string.Empty;
                            }
                            else
                            {
                                drInsert[dgvSourceGrid.Columns[intCol].Name.ToString().Trim()] = dgvSourceGrid.Rows[intRow].Cells[dgvSourceGrid.Columns[intCol].Name].Value;
                                if (dgvSourceGrid.Columns[intCol].Name.ToString().Trim().Contains("ChargePaidBy") == true)
                                {
                                    set_PayerID(ref dgvSourceGrid, intRow, dgvSourceGrid.Rows[intRow].Cells[dgvSourceGrid.Columns[intCol].Name].Value.ToString());
                                }
                                strIDDetails = string.Empty;
                            }
                        }
                    }
                    dtStorage.Rows.Add(drInsert);
                    strIDDetails = string.Empty;
                }
                bolStatus = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_InsertRecordsFromGrid"); 
            }
            return bolStatus;
        }

        private string get_ConcatenatedAdditionalServices(DataTable dtSource)
        {
            string strConcatenated = string.Empty;
            try
            {
                DataRow[] drCheck = dtSource.Select("", "ccitemcode asc");
                if (drCheck.Length > 0)
                {
                    for (int intRow = 0; intRow < drCheck.Length; intRow++)
                    {
                        if (intRow < drCheck.Length - 1)
                        {
                            strConcatenated += drCheck[intRow]["ccitemcode"].ToString() + "+";
                        }
                        else
                        {
                            strConcatenated += drCheck[intRow]["ccitemcode"].ToString();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_ConcatenatedAdditionalServices"); 
            }

            return strConcatenated;
        }

        private string get_ConcatenatedItemCodes(RadGridView dgvSource)
        {
            string strString = string.Empty;
            try
            {
                //ccitemcode
                for (int intRow = 0; intRow < dgvSource.Rows.Count ; intRow ++)
                {
                   strString += dgvSource.Rows[intRow].Cells["ccitemcode"].Value;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " get_ConcatenatedItemCodes"); 
            }
            return strString; 
        }


        //The user must not be allowed to save two equal sets of additional charges 
        //both origin and destination even w/ different description

        public DataTable get_OrigindtCharges
        {
            get
            {
                return this.dtOrigin;
            }
        }

        public DataTable get_DestinationdtCharges
        {
            get
            {
                return this.dtDestination;
            }
        }

        private void set_CreateSetNewHeaderRow()
        {
            try
            {
                if (_BUS.set_CreateNewRowAdditionalServicesHeader() == true)
                {
                    
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_CreateSetNewHeaderRow"); 
            }
        }

        private bool set_ApplyAndOK()
        {
            bool bolStatus = false;
            try
            {
                if (mcmbTransactions.Text.Trim() != string.Empty)
                {
                    //ADD VALIDATIONS and checkings HERE 
                    set_AdditionalServicesHeaderID();
                    _BUS.getset_AdditionalServicesHeaderID = get_SalesTermAdditionalHeaderID; ;
                    _BUS.getset_SalesTermHeaderID = getset_SalesTermSetupHeaderID;
                    //_BUS.GETSET_getset_AdditionalServicesHeaderID
                    epDescription.Clear();
                    this.dtOrigin = get_GenerateColumns();
   
                    //SalesTermSetupHeadersID + ShipperID + ConsigneeID + GRN + currentDateTime 
                    if (_BUS.get_CheckHeaderAndDetailsLoaded() == true)
                    {
                        _BUS.getset_AdditionalServicesDescription = mcmbTransactions.Text.Trim();
                        _BUS.set_CreateNewRowAdditionalServicesHeader();
                     
                        string strConcatenatedOrigin = get_ConcatenatedItemCodes(dgvAdditionalChargesOrigin);
                        string strConcatenatedDestination = get_ConcatenatedItemCodes(dgvAdditionalChargesDestination);

                        if (get_TransferRecordsFromGrid(ref this.dtOrigin, ref dgvAdditionalChargesOrigin, strConcatenatedOrigin, "Origin") == true)
                        {
                            //if (get_TransferRecordsFromGrid(ref this.dtDestination, dgvAdditionalChargesDestination, strConcatenatedDestination, "Destination") == true)
                            //{
                                _BUS.set_TransferToDataset(this.dtOrigin);
                            //        _BUS.set_TransferToDataset(this.dtDestination);
                            bolApplied = true;
                            bolStatus = true;
                        }
                      //  }
                    }
                }
                else
                {
                    bolApplied = false;
                    bolStatus = false;
                    epDescription.SetError(mcmbTransactions, "Empty.");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ApplyAndOK"); 
            }
            return bolStatus;
        }

        private void btnApply_Click(object sender, EventArgs e)
        {
            try
            {
                if (set_ApplyAndOK() == true)
                {
                    this.bolApplied = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " btnApply_Click"); 
            }
        }

        public DataRow[] get_OriginCharges()
        {
            DataRow[] drcheck = { };
            if (dtOrigin != null && dtOrigin.Rows.Count > 0)
            {
                drcheck = this.dtOrigin.Select();
            }
            return drcheck ;
        }
        public DataRow[] get_DestinationCharges()
        {
             DataRow[] drcheck = { };
            if (dtDestination != null && dtDestination.Rows.Count > 0)
            {
                drcheck = this.dtDestination.Select();
            }
            return drcheck;
        }

        private void mcmbTransactions_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                //getset_3rdParty

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " mcmbTransactions_SelectedIndexChanged"); 
            }
        }

        private bool get_CheckLoaded()
        {
            bool bolStatus = false;
            if (_BUS.set_LoadTransactions(string.Empty) == true && _BUS.set_LoadAdditionalServicesHeader(string.Empty) == true)
            {
                bolStatus = true;
            }
            return bolStatus;
        }

        private void cbbNew_Click(object sender, EventArgs e)
        {
            try
            {
                if (get_CheckLoaded() == true)
                {
                    set_ClearFields();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " cbbNew_Click"); 
            }
        }

        private void set_ClearFields()
        {
            try
            {
                mcmbTransactions.Text = string.Empty;
                txtSetID.Text = string.Empty;
                //chkPaid3rdParty.Checked = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_ClearFields"); 
            }
        }

        private void set_FindCharges(ref RadGridView dgvOriginDestination, bool bolOriginDestination)
        {
            try
            {
                bool bolSetToGrid = false;
                using (frmFindCharges charges = new frmFindCharges())
                {
                    GridCellElement cellElement = dgvOriginDestination.TableElement.GetCellElement(dgvOriginDestination.CurrentRow, dgvOriginDestination.CurrentColumn);
                    Point cellLocation = dgvOriginDestination.PointToScreen(cellElement.ControlBoundingRectangle.Location);
                    charges.set_NewLocation(cellLocation.X, cellLocation.Y + dgvOriginDestination.CurrentCell.Size.Height);
                    charges.set_DAL = _BUS.get_DAL;
                    charges.getset_SalesTermSetupHeaderID = this.getset_SalesTermSetupHeaderID;

                    if (charges.ShowDialog() == DialogResult.OK)
                    {
                        if (charges.getset_Code.ToUpper().Contains("INLAN") == true)
                        {
                            //call the find module to search the areas
                            //the source of these areas is from the inland charges setup
                            using (frmFindCompany PortAreas = new frmFindCompany("Area"))
                            {
                                PortAreas.getset_SearchType = "Area";
                                PortAreas.getset_PortAreaID = getset_PortID;
                                DialogResult diar = PortAreas.ShowDialog();
                                if (diar == DialogResult.OK)
                                {
                                    using (clsBUSInland Inland = new clsBUSInland())
                                    {
                                        if (Inland.get_InlandDetails(PortAreas.get_Code, getset_PortID) == true)
                                        {
                                            dgvOriginDestination.CurrentRow.Cells["ccitemcode"].Value = charges.getset_Code;
                                            dgvOriginDestination.CurrentRow.Cells["CodeDescription"].Value = charges.getset_Description + " - " + Inland.getset_AreaDescription;  
                                            dgvOriginDestination.CurrentRow.Cells["SalesTermSetupAdditionalChargesID"].Value = charges.getset_SetupDetailsID;
                                            dgvOriginDestination.CurrentRow.Cells["InLandSetupChargesID"].Value = Inland.getset_InLandSetupChargesID;
                                            bolSetToGrid = true;
                                        }
                                    }
                                }
                            }
                        }
                        else
                        {
                            dgvOriginDestination.CurrentRow.Cells["ccitemcode"].Value = charges.getset_Code;
                            dgvOriginDestination.CurrentRow.Cells["CodeDescription"].Value = charges.getset_Description;
                            dgvOriginDestination.CurrentRow.Cells["SalesTermSetupAdditionalChargesID"].Value = charges.getset_SetupDetailsID;
                        }
                        
                       
                            if (charges.getset_Code.ToUpper().Contains("INLAN") == true)
                            {
                                if (bolSetToGrid == true)
                                {
                                    set_LoadGridOriginDestinationRefToGrid(ref dgvOriginDestination, charges.get_ChargeDetails());
                                }
                            }
                            else
                            {
                                set_LoadGridOriginDestinationRefToGrid(ref dgvOriginDestination, charges.get_ChargeDetails());
                            }
                        //}
                        //else
                        //{
                        //    set_LoadGridOriginDestinationRefToGrid(ref dgvOriginDestination, charges.get_ChargeDetails());
                        //}
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_FindCharges");
            }
        }

        private void dgvAdditionalChargesOrigin_CellClick(object sender, GridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 5 || e.ColumnIndex == 6)
                {
                    dgvAdditionalChargesOrigin.ClearSelection();  
                    set_FindCharges(ref dgvAdditionalChargesOrigin, true); 
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " dgvAdditionalChargesOrigin_CellClick"); 
            }
        }

        private void dgvDestination_CellClick(object sender, GridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4 || e.ColumnIndex == 5)
            {
                dgvAdditionalChargesOrigin.ClearSelection();  
                set_FindCharges(ref dgvAdditionalChargesDestination, false);
            }
        }

        private void dgvAdditionalChargesOrigin_CurrentRowChanged(object sender, CurrentRowChangedEventArgs e)
        {
            if (e.CurrentRow.Index > -1)
            {
                //set_CurrentRowchangedAdditionalCharges(e, ref dgvAdditionalChargesDestination, "Origin");
            }
        }

        private void set_CurrentRowchangedAdditionalCharges(CurrentRowChangedEventArgs e, ref RadGridView dgvOriginDestination, string strType)
        {
            //try
            //{
            //    bool bolOriginDestination = false;
            //    if (strType.Trim() == "Origin")
            //    { bolOriginDestination = true; }

            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message + " dgvOrigin_CurrentRowChanged");
            //}
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.bolApplied == false)
                {
                    if (set_ApplyAndOK() == true)
                    {
                        this.bolApplied = true;
                        DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    DialogResult = DialogResult.OK;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " btnOK_Click"); 
            }
        }

        private void dgvAdditionalChargesDestination_CellClick(object sender, GridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 5 || e.ColumnIndex == 6)
            {
                dgvAdditionalChargesDestination.ClearSelection();
                set_FindCharges(ref  dgvAdditionalChargesDestination, true);
            }
        }

        private void dgvAdditionalChargesOrigin_CellValueChanged(object sender, GridViewCellEventArgs e)
        {
            try
            {
                if (e.ColumnIndex == 26)
                {
                    if (e.Value != null && (string)e.Value != string.Empty)
                    {
                        if (e.Value.ToString() == "Shipper")
                        {
                            dgvAdditionalChargesOrigin.CurrentRow.Cells["comid"].Value = txtShipperID.Text.Trim();
                        }
                        else if (e.Value.ToString() == "Consignee")
                        {
                            dgvAdditionalChargesOrigin.CurrentRow.Cells["comid"].Value = txtConsigneeID.Text.Trim();
                        }
                        else if (e.Value.ToString() == "3rd Party" && txt3rdPartyID.Text.Trim() != string.Empty)
                        {
                            dgvAdditionalChargesOrigin.CurrentRow.Cells["comid"].Value = txt3rdPartyID.Text.Trim();
                        }
                        else if (e.Value.ToString() == "3rd Party" && txt3rdPartyID.Text.Trim() == string.Empty)
                        {
                            MessageBox.Show("No Selected Third party.");
                            dgvAdditionalChargesOrigin.CurrentRow.Cells["comid"].Value = string.Empty;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " dgvAdditionalChargesOrigin_CellValueChanged"); 
            }
        }

     
    }
}
